<template>
  <div class="pad-20 bgc-default" v-loading="loading">
    <!-- 订单信息 -->
    <div>
      <div class="font-20 mar-b-10">订单信息</div>
      <div class="bg-color-white pad-20">
        <!-- tab块 -->
        <template v-if="tabModel">
          <div class="mar-b-10">
            <el-tabs v-model="tabModel" type="card" @tab-click="doChangeTab">
              <el-tab-pane :label="'合并单【' + mergeNo + '】'" :name="mergeNo"> </el-tab-pane>
              <template v-for="(item, key) in tabList">
                <el-tab-pane :key="key" :label="'被合单【' + item + '】'" :name="item"></el-tab-pane>
              </template>
            </el-tabs>
          </div>
        </template>
        <!-- 顶部信息 -->
        <div class="font-18">
          <span>{{ dict.orderStatus[thirdOrderObj.orderStatus] }}</span>
          <span class="pad-l-5 pad-r-5">—</span>
          <!-- <span :class="thirdOrderObj.afterSaleStatus == 0 ? 'font-color' : 'font-red'">{{ dict.afterSaleStatus[thirdOrderObj.afterSaleStatus] }}</span> -->
          <span :class="thirdOrderObj.exceptionTypeList.length == 0 ? 'font-blue' : 'font-red'">
            <template v-if="thirdOrderObj.exceptionTypeList.length == 0">
              <span>（无异常）</span>
            </template>
            <template v-else>
              （{{ dict.exceptionType[thirdOrderObj.exceptionTypeList[0]] }}）
              <el-tooltip placement="top" effect="light" v-if="thirdOrderObj.exceptionTypeList.length > 1">
                <template v-for="(item,i) in thirdOrderObj.exceptionTypeList">
                  <div slot="content" :key="i">{{dict.exceptionType[item]}}<br/></div>
                </template>
                <i class="el-icon-warning"></i>
              </el-tooltip>
            </template>
          </span>
        </div>
        <hr>
        <el-row>
          <template v-if="thirdOrderObj.encryptReceiveFlag == 1">
            <el-tooltip class="item" effect="dark" content="点击查看收货信息" placement="top-start">
              <img :src="isLock ? lockIcon : unlockIcon" class="width-24 cursor-p" style="position: absolute; right: 10px;" @click="doDecrypt(0)">
            </el-tooltip>
          </template>
          <!-- 左侧信息 -->
          <el-col :span="12">
            <table class="base-info">
              <tr>
                <td class="left">平台类型：</td>
                <td class="right">
                  <span>{{ dict.platformType[thirdOrderObj.platformType] }}</span>
                </td>
              </tr>
              <tr>
                <td class="left">平台订单号：</td>
                <td class="right">
                  <span>{{ thirdOrderObj.externalOrderNo }}</span>
                  <a href="javascript:;" @click="doCopy(thirdOrderObj.externalOrderNo, $event)"><span class="mar-l-10 font-blue">复制</span></a>
                </td>
              </tr>
              <tr>
                <td class="left">零售订单号：</td>
                <td class="right">{{ thirdOrderObj.orderNo ||  '（未生成）' }}</td>
              </tr>
              <tr>
                <td class="left">订单类型：</td>
                <td class="right">{{ dict.orderType[thirdOrderObj.orderType] }}</td>
              </tr>
              <tr>
                <td class="left">支付类型：</td>
                <td class="right">{{ dict.payType[thirdOrderObj.payType] ||  '（未知）' }}</td>
              </tr>
              <tr>
                <td class="left">是否一次性付款：</td>
                <td class="right">{{thirdOrderObj.stepPayAll === 1 ? '是' : '否'}}</td>
              </tr>
              <tr>
                <td class="left">买家昵称：</td>
                <td class="right">{{ thirdOrderObj.buyerNick }}</td>
              </tr>
              <tr>
                <td class="left">买家留言：</td>
                <td class="right">
                  <el-input type="textarea" :rows="3" class="width-300" v-model="thirdOrderObj.buyerWords" :disabled="!editFlag"/>
                </td>
              </tr>
              <tr>
                <td class="left">卖家备注：</td>
                <td class="right">
                  <el-input type="textarea" :rows="3" class="width-300" v-model="thirdOrderObj.sellerWords" :disabled="!editFlag"/>
                </td>
              </tr>
              <tr>
                <td class="left">发货快递：</td>
                <td class="right">
                  <template v-if="thirdOrderObj.logisticsId">
                    <span v-if="thirdOrderObj.expressName">{{ thirdOrderObj.expressName }}</span>
                    <span v-else class="font-red">物流编码不匹配</span>
                    <el-tooltip placement="top" effect="light">
                      <div slot="content">
                        <div>平台物流编码：{{ thirdOrderObj.logisticsId }}</div>
                      </div>
                      <i class="el-icon-warning"></i>
                    </el-tooltip>
                  </template>
                </td>
              </tr>
              <tr>
                <td class="left">快递单号：</td>
                <td class="right">{{ thirdOrderObj.logisticsCode }}</td>
              </tr>
              <tr>
                <td class="left">
                  <el-button v-if="editFlag" type="text" size="medium" class="mar-t-30" @click="doSave()">更新订单其他信息</el-button>
                </td>
              </tr>
            </table>
          </el-col>
          <!-- 右侧信息 -->
          <el-col :span="12">
            <table class="base-info">
              <tr><strong>平台收货信息</strong></tr>
              <tr>
                <td class="left">收货人：</td>
                <td class="right">
                  <span>{{ thirdOrderObj.postReceiver }}</span>
                </td>
              </tr>
              <tr>
                <td class="left">收货人电话：</td>
                <td class="right">
                  <span>{{ thirdOrderObj.postTel }}</span>
                </td>
              </tr>
              <tr>
                <td class="left">收货地址：</td>
                <td class="right">
                  <div class="inline-flex" style="flex-direction: column;align-items: baseline;">
                    <div>
                      <span>{{ thirdOrderObj.postProvince }}</span>
                      <span>&nbsp;</span>
                      <span>{{ thirdOrderObj.postCity }}</span>
                      <span>&nbsp;</span>
                      <span>{{ thirdOrderObj.postTown }}</span>
                    </div>
                    <div>
                      <span>{{ thirdOrderObj.postDetail }}</span>
                      <el-tooltip placement="top" effect="light">
                        <div slot="content">
                          <div>平台地址编码</div>
                          <div>{{ thirdOrderObj.postProvince }}（{{ thirdOrderObj.postProvinceCode }}）</div>
                          <div>{{ thirdOrderObj.postCity }}（{{ thirdOrderObj.postCityCode }}）</div>
                          <div>{{ thirdOrderObj.postTown }}（{{ thirdOrderObj.postTownCode }}）</div>
                        </div>
                        <i class="el-icon-warning mar-l-10"></i>
                      </el-tooltip>
                    </div>
                  </div>
                </td>
              </tr>

              <tr><strong>当前收货信息</strong></tr>
              <tr>
                <td class="left">收货人：</td>
                <td class="right">
                  <el-input v-model="thirdOrderObj.customerName" :disabled="true" class="width-300"></el-input>
                </td>
              </tr>
              <tr>
                <td class="left">收货人电话：</td>
                <td class="right">
                  <div class="inline-flex">
                    <el-input v-model="thirdOrderObj.customerPhone" :disabled="true" class="width-300"></el-input>
                    <el-button v-if="thirdOrderObj.platformType == 4 && thirdOrderObj.pddVirtualNumberType == 1" type="text" class="mar-l-10" @click="pddVirtualNumberVisible = true">隐私号可直接发货/联系消费者</el-button>
                  </div>
                </td>
              </tr>
              <tr>
                <td class="left">收货地址：</td>
                <td class="right">
                  <el-select class="mar-r-3 width-140" v-model="thirdOrderObj.customerProvinceCode" :disabled="!editFlag || isLock || kuaiShouFlag|| openAlibabaFlag" placeholder="请选择省份" @change="doChangeCity(thirdOrderObj.customerProvinceCode)">
                    <el-option v-for="item in provinceList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode">
                    </el-option>
                  </el-select>
                  <el-select class="mar-r-3 width-140" v-model="thirdOrderObj.customerCityCode" :disabled="!editFlag || isLock || kuaiShouFlag|| openAlibabaFlag" placeholder="请选择城市" @change="doChangeDistrict(thirdOrderObj.customerCityCode)">
                    <el-option v-for="item in cityList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode">
                    </el-option>
                  </el-select>
                  <el-select class="width-140" v-model="thirdOrderObj.customerDistrictCode" :disabled="!editFlag || isLock || kuaiShouFlag|| openAlibabaFlag" placeholder="请选择区县">
                    <el-option v-for="item in districtList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode">
                    </el-option>
                  </el-select>
                  <div class="mar-t-5">
                    <el-input v-model="thirdOrderObj.customerAddress" :disabled="!editFlag || isLock || kuaiShouFlag || openAlibabaFlag" style="width: 435px"></el-input>
                    <!-- 按钮区 -->
                    <template v-if="thirdOrderObj.changeReceiverStatus == 10">
                      <el-button type="text" size="medium" style="float: right;" @click="doAuditReceiveAddress">
                        <span class="font-red">顾客申请修改收货信息，</span>
                        <span class="font-blue">点击审核</span>
                      </el-button>
                    </template>

                    <template v-if="thirdOrderObj.changeReceiverStatus == 20">
                      <el-button type="text" size="medium" style="float: right;">
                        <span class="font-red">顾客申请修改收货信息，已审核，等待平台处理</span>
                      </el-button>
                    </template>

                    <template v-if="editFlag && !isLock && !kuaiShouFlag && thirdOrderObj.changeReceiverStatus != 10 && thirdOrderObj.changeReceiverStatus != 20 && !openAlibabaFlag">
                      <el-button type="text" size="medium" style="float: right;" @click="doSaveReceiveInfo()">更新并同步收货信息</el-button>
                    </template>
                  </div>
                </td>
              </tr>
              <tr v-if="thirdOrderObj.platformType === 4 && !isLock">
                <td class="left"></td>
                <td class="right">
                  <div class="font-orange">
                    <i class="el-icon-warning"></i>
                    <span>修改收货人姓名及详细地址请勿删除末尾“[分机号]”，如误删请刷新重新解密</span>
                  </div>
                </td>
              </tr>
              <tr>
                <td colspan="2"><hr class="mar-t-10 mar-b-10"></td>
              </tr> 
              <tr>
                <td class="left">所属店铺：</td>
                <td class="right">{{ thirdOrderObj.thirdShop ? thirdOrderObj.thirdShop.shopName : '（店铺未找到）' }}</td>
              </tr>
              <tr v-if="subOrderList.length > 0">
                <td class="left">商品摘要：</td>
                <td class="right"> 
                  <span>共{{ subOrderList.length }}件</span>
                  <span>，商品金额{{ thirdOrderObj.orderGoodsAmount }}元</span>
                  <span>，运费{{ thirdOrderObj.postAmount }}元</span>
                  <span>，合计{{ thirdOrderObj.orderAmount }}元</span>
                </td>
              </tr>
              
              <tr v-if="thirdOrderObj.stepPayAll === 0">
                <td class="left" valign="top">阶段付款：</td>
                <td class="right">
                  <div v-for="(item, index) of orderStepList" :key="index">
                      <span>第{{ item.stepNo }}次付款 &nbsp; {{ item.lastStep === 1 ? '（最后一个阶段）' : '' }}  &nbsp;
                        <span class="font-red">{{ item.payStatus === 1 ? '未付款' : '已付款' }}</span>  &nbsp;&nbsp; 应付款：¥{{ item.payFee }}  &nbsp;&nbsp; 已付款：¥{{ item.paidFee }}<br>
                      付款时间：{{ item.gmtPay }}
                      </span>
                  </div>
                </td>
              </tr>
              <tr>
                <td class="left">创建时间：</td>
                <td class="right">{{ thirdOrderObj.thirdPlatformCreateTime }}</td>
              </tr>
              <tr>
                <td class="left">付款时间：</td>
                <td class="right">{{ thirdOrderObj.payTime }}</td>
              </tr>
              <tr>
                <td class="left">同步时间：</td>
                <td class="right">{{ thirdOrderObj.syncTime }}</td>
              </tr>
            </table>
          </el-col>
        </el-row>
      </div>
    </div>

    <!-- 订单商品明细 -->
    <div class="mar-t-20">
      <span class="font-20">订单商品明细</span>
      <div class="mar-t-10 bg-color-white pad-20">
        <div style="text-align: right;" v-if="editFlag">
          <el-button type="text" size="medium" @click="doResetAll">全部重新添加</el-button>
          <!-- <el-button type="text" size="medium" @click="doDeleteAll">删除所有商品</el-button> -->
        </div>

        <el-table :data="subOrderList" border row-key="rowKey" :tree-props="{children: 'comboSubList'}">>
          <el-table-column label="平台商品明细" align="center" label-class-name="font-w">
            <el-table-column min-width="200px" label="子单号" prop="subExternalOrderNo" resizable show-overflow-tooltip>
              <template slot-scope="scope">
                <span title="赠品" v-if="scope.row.giftFlag == 1"><svg-icon icon-class="gift" class="font-20"/></span>
                <span>{{ scope.row.subExternalOrderNo }}</span>
                <div v-if="scope.row.delFlag == 1" class="font-red">（已删除）</div>
                <div v-if="scope.row.afterSaleStatus > 0" class="font-red">{{ dict.afterSaleStatus[scope.row.afterSaleStatus] }}</div>
              </template>
            </el-table-column>
            <el-table-column min-width="220px" label="商品名称">
              <template slot-scope="scope" v-if="scope.row.productId">
                <div class="line-2 font-w mar-b-5">{{ scope.row.productName }}</div>
                <div>
                  <span>平台编码：</span>
                  <span class="font-blue">{{ scope.row.productCode }}</span>
                </div>
                <div class="line-2" :title="scope.row.productSkuDetail">
                  <span>商品规格：</span>
                  <span class="font-blue">{{ scope.row.productSkuDetail }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column width="160px" label="推广者" align="left">
              <template slot-scope="scope">
                <div class="line-1" v-if="scope.row.productDistributorName" :title="scope.row.productDistributorName">昵称：{{ scope.row.productDistributorName }}</div>
                <div class="line-1" v-if="scope.row.productDistributorId" :title="scope.row.productDistributorId">id：{{ scope.row.productDistributorId }}</div>
              </template>
            </el-table-column>
            <el-table-column width="120px" label="数量" align="left">
              <template slot-scope="scope">
                <div>商品数量：{{ scope.row.goodsNum }}</div>
                <div>发货数量：{{ scope.row.deliveryNum }}</div>
                <div>售后数量：<span :class="scope.row.afterSaleGoodsNum > 0 ? 'font-red' : ''">{{ scope.row.afterSaleGoodsNum }}</span></div>
              </template>
            </el-table-column>
            <el-table-column width="160px" label="单价 / 金额" align="left">
              <template slot-scope="scope">
                <div>商品单价: ￥{{ scope.row.productPrice }}</div>
                <div>商品金额: ￥{{ (scope.row.productPrice * scope.row.goodsNum).toFixed(2) }}</div>
                <div>实付金额: ￥{{ scope.row.productPayAmount }}</div>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column label="系统商品明细" align="center" label-class-name="font-w">
             <el-table-column width="120px" label="添加结果" align="left">
              <template slot-scope="scope">
                <div class="line-2" 
                  :class="scope.row.addResult == '成功添加' ? '' : 'font-red'" 
                  :title="scope.row.addResult">
                  {{ scope.row.addResult }}
                </div>
              </template>
            </el-table-column>
            <el-table-column min-width="200px" label="商品名称">
              <template slot-scope="scope">
                <div v-if="scope.row.goodsId">
                  <div class="line-2 font-w mar-b-5" :title="scope.row.goodsTitle">{{ scope.row.goodsTitle }}</div>
                  <div>
                    <span>外部编码：</span>
                    <span class="font-blue">{{ scope.row.externalCode }}</span>
                  </div>
                  <div class="line-2" :title="scope.row.productSkuDetail">
                    <span>商品规格：</span>
                    <span class="font-blue">{{ scope.row.skuDetail }}</span>
                  </div>
                </div>
                <div v-else>（商品未找到）</div>
              </template>
            </el-table-column>
            <el-table-column width="90px" label="商品类型" prop="comboType" align="center">
              <template slot-scope="scope">
                <div>{{ dict.comboType[scope.row.comboType] }}</div>
              </template>
            </el-table-column>
            <el-table-column width="90px" label="操作" align="right" v-if="editFlag">
              <template slot-scope="scope">
                <template v-if="scope.row.delFlag != 1">
                  <!-- 组合子商品按钮 -->
                  <template v-if="scope.row.thirdSubOrderComboId">
                    <el-button type="text" size="medium" class="table-btn" @click="doChangeGoods(scope.row)">修改商品</el-button>
                    <el-button type="text" size="medium" class="table-btn" v-if="scope.row.skuId" @click="doChangeGoodsSku(scope.row)">修改规格</el-button>
                  </template>
                  <!-- 平台子单商品按钮 -->
                  <template v-else>
                    <template v-if="scope.row.originalFlag == 1">
                      <el-button type="text" size="medium" class="table-btn" @click="doChangeGoods(scope.row)">修改商品</el-button>
                      <el-button type="text" size="medium" class="table-btn" v-if="scope.row.skuId" @click="doChangeGoodsSku(scope.row)">修改规格</el-button>
                      <!-- <el-button type="text" size="medium" class="table-btn" v-if="scope.row.addResult == '成功添加'" @click="doChangeGoodsNum(scope.row)">添加赠品</el-button> -->
                      <el-button type="text" size="medium" class="table-btn" @click="doResetSubOrder(scope.row)">重新添加</el-button>
                    </template>
                    <template v-else>
                      <el-button type="text" size="medium" class="table-btn" @click="doDeleteSubOrder(scope.row)">删除</el-button>
                    </template>
                  </template>
                </template>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 底部按钮区 -->
    <div class="pad-20" align="center" v-if="!mergeUsedFlag">
      <el-button v-if="thirdOrderObj.generateFlag == 1" type="primary" @click="doGenerate">生成</el-button>
      <el-button v-if="prevId" type="primary" @click="doJumpPrev">上一笔</el-button>
      <el-button v-if="nextId" type="primary" @click="doJumpNext">下一笔</el-button>
      <el-button v-if="thirdOrderObj.syncStatus != 0" @click="doDelete">{{ thirdOrderObj.mergeType == 1 ? '重新同步' : '删除' }}</el-button>
    </div>

    <!-- 修改数量 -->
    <el-dialog width="400px" v-el-drag-dialog title="修改数量" :visible.sync="updateGoodsNumVisible">
      <el-form ref="goodNumForm" :model="goodNumForm" :rules="rules" label-width="100px" class="pad-r-30">
        <el-form-item label="商品数量" prop="goodsNum">
          <el-input v-model="goodNumForm.goodsNum" @keyup.native="goodNumForm.goodsNum = checkInputPositiveNum(goodNumForm.goodsNum)"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="updateGoodsNumVisible = false">取消</el-button>
        <el-button type="primary" @click="updateGoodsNum">确定</el-button>
      </div>
    </el-dialog>

    <!-- 选择商品dialog -->
    <el-dialog width="1000px" v-el-drag-dialog title="选择商品" :visible.sync="selectSkuVisible">
      <select-goods-sku :showFlag="selectSkuVisible" 
        :skuFlag="1" 
        :crossBorderType="1"
        :goodsId="selectedGoodsId" 
        :platformType="thirdOrderObj.platformType" 
        @callback="doCallbackSelect">
      </select-goods-sku>
    </el-dialog>

    <!-- 审核收货信息dialog -->
    <el-dialog width="670px" title="审核收货信息" v-el-drag-dialog :visible.sync="auditReceiveVisible">
      <third-order-audit-receive :showFlag="auditReceiveVisible" :thirdOrderId="thirdOrderObj.thirdOrderId" @callback="doCallbackAuditReceive"></third-order-audit-receive>
    </el-dialog>

    <!-- 拼多多隐私号说明dialog -->
    <el-dialog width="670px" title="隐私号说明" :visible.sync="pddVirtualNumberVisible">
      <pdd-virtual-number :showFlag="pddVirtualNumberVisible" 
        :externalOrderNo="thirdOrderObj.externalOrderNo" 
        :platformType="thirdOrderObj.platformType" 
        :virtualNumber="decryptInfo.receiverPhone">
      </pdd-virtual-number>
    </el-dialog>

  </div>
</template>

<script>
  import { getDictByGroupName } from '@/api/common/common'
  import { listProvince, listCity, listDistrict } from '@/api/area/area'
  import {
    getThirdOrder,
    getByNoAndType,
    deleteThirdOrder,
    saveThirdOrder,
    doGenerateOrder,
    getPrevId,
    getNextId,
    decryptReceiveInfo,
    updateReceiveInfo
  } from '@/api/goods/thirdOrder'
  import {
    addGift,
    doReset,
    doChange,
    deleteSubOrder
  } from '@/api/goods/thirdSubOrder'
  import { doChangeCombo } from '@/api/goods/thirdSubOrderCombo'
  import clipboard from '@/utils/clipboard'
  import elDragDialog from '@/directive/el-dragDialog'
  import selectGoodsSku from '@/views/goods/order/components/select-goods-sku'
  import thirdOrderAuditReceive from '@/views/goods/order/components/third-order-audit-receive'
  import pddVirtualNumber from '@/views/goods/order/components/pdd-virtual-number'
  import unlockIcon from '@/assets/images/unlock-icon.png'
  import lockIcon from '@/assets/images/lock-icon.png'

  export default {
    directives: {
      elDragDialog
    },
    components: {
      selectGoodsSku, thirdOrderAuditReceive, pddVirtualNumber
    },
    data() {
      return {
        // 第三方订单对象
        thirdOrderObj: {
          thirdOrderId: '',
          enterpriseExpressId: '',
          orderStatus: '',
          postReceiver: '',
          postTel: '',
          postDetail: '',
          customerProvinceCode: '',
          customerCityCode: '',
          customerDistrictCode: '',
          customerAddress: '',
          subOrders: [],
          orderStepList: [],
          exceptionTypeList: [],
          platformType: ''
        },
        // 订单商品集合
        subOrderList: [],
        // 数据字典
        dict: {
          orderStatus: {},
          orderType: {},
          afterSaleStatus: {},
          comboType: {},
          payType: {},
          platformType: {},
          exceptionType: {}
        },
        // 解密信息对象
        decryptInfo: {
          address: '',
          receiverName: '',
          receiverPhone: ''
        },
        // 省集合
        provinceList: [],
        // 市集合
        cityList: [],
        // 区集合
        districtList: [],
        // 修改数量表单
        goodNumForm: {
          thirdSubOrderId: '',
          goodsNum: ''
        },
        // 子单表单
        orderGoodsForm: {
          thirdSubOrderId: '',
          thirdOrderId: '',
          skuId: '',
          goodsId: ''
        },
        rules: {
          goodsNum: [
            { required: true, message: '商品数量不能为空', trigger: 'blur' }
          ]
        },
        // tab相关
        tabModel: '',
        mergeNo: '',
        tabList: [],
        // 选中的商品id
        selectedGoodsId: '',
        loading: false,
        selectSkuVisible: false,
        updateGoodsNumVisible: false,
        // 审核收货信息visible
        auditReceiveVisible: false,
        pddVirtualNumberVisible: false,
        // 上一笔id
        prevId: '',
        // 下一笔id
        nextId: '',
        // 锁图标
        lockIcon,
        unlockIcon,
        // 锁标识
        isLock: false,
        // 编辑flag
        editFlag: false,
        // 快手平台flag
        kuaiShouFlag: false,
        // 1688平台flag
        openAlibabaFlag: false,
        // 合并flag
        mergeFlag: false,
        // 被合并flag
        mergeUsedFlag: false,
        // 第三方订单分阶段付款记录
        orderStepList: []
      }
    },
    // 初始化页面
    created() {
      // 获取省信息
      listProvince().then(response => {
        this.provinceList = response.data
      })
      // 获取数据字典
      getDictByGroupName('ThirdOrderDTO').then(response => {
        if (response.isError) return
        Object.assign(this.dict, response.data)
      })
      getDictByGroupName('ThirdSubOrderDTO.afterSaleStatus').then(response => {
        if (response.isError) return
        Object.assign(this.dict, response.data)
      })
      // 获取数据字典
      getDictByGroupName('ProjectGoodsDTO.comboType').then(response => {
        if (response.isError) return
        Object.assign(this.dict, response.data)
      })
      const thirdOrderId = this.getCurrentPage().query.thirdOrderId
      this.thirdOrderObj.thirdOrderId = thirdOrderId
      this.init()
    },
    methods: {
      // 初始化
      init() {
        this.loading = true
        getThirdOrder(this.thirdOrderObj.thirdOrderId).then(response => {
          this.initAfter(response)
        })
      },
      initByNo() {
        this.loading = true
        getByNoAndType(this.tabModel, this.thirdOrderObj.platformType).then(response => {
          this.initAfter(response)
        })
      },
      // 后处理
      initAfter(response) {
        this.loading = false
        if (response.isError) return
        Object.assign(this.thirdOrderObj, response.data)
        this.mergeFlag = this.thirdOrderObj.mergeType === 2
        this.kuaiShouFlag = this.thirdOrderObj.platformType === 2
        this.openAlibabaFlag = this.thirdOrderObj.platformType === 7
        this.editFlag = this.thirdOrderObj.generateFlag === 1 && this.thirdOrderObj.orderStatus === 1 && !this.mergeFlag
        this.isLock = this.thirdOrderObj.encryptReceiveFlag === 1
        this.subOrderList = this.thirdOrderObj.subOrders
        this.orderStepList = this.thirdOrderObj.thirdOrderSteps
        this.mergeUsedFlag = this.thirdOrderObj.mergeType === 3
        if (this.mergeFlag && !this.tabModel) {
          this.tabModel = this.thirdOrderObj.externalOrderNo
          this.mergeNo = this.thirdOrderObj.externalOrderNo
          this.tabList = this.thirdOrderObj.mergeNoArr.split(',')
        }
        if (this.mergeUsedFlag) {
          this.editFlag = false
        } else {
          const thirdOrderId = this.thirdOrderObj.thirdOrderId
          getPrevId(thirdOrderId).then(response => {
            if (response.isError) return
            this.prevId = response.data
          })
          getNextId(thirdOrderId).then(response => {
            if (response.isError) return
            this.nextId = response.data
          })
        }
        this.doChangeCity(this.thirdOrderObj.customerProvinceCode, this.thirdOrderObj.customerCityCode, this.thirdOrderObj.customerDistrictCode)
      },
      // tab切换事件
      doChangeTab() {
        this.initByNo()
      },
      // 复制事件
      doCopy(text, event) {
        clipboard(text, event)
      },
      // 解密事件
      doDecrypt(decryptReportType) {
        if (!this.isLock) {
          // 不再解密
          return
        }
        this.loading = true
        decryptReceiveInfo(this.thirdOrderObj.externalOrderNo, this.thirdOrderObj.platformType, decryptReportType).then(response => {
          this.loading = false
          if (response.isError) return
          this.isLock = false
          const data = response.data
          this.decryptInfo.receiverName = data.postReceiver
          this.decryptInfo.receiverPhone = data.postTel
          this.decryptInfo.address = data.postDetail
          this.thirdOrderObj.postReceiver = data.postReceiver
          this.thirdOrderObj.postTel = data.postTel
          this.thirdOrderObj.postDetail = data.postDetail
          this.thirdOrderObj.customerName = data.customerName
          this.thirdOrderObj.customerPhone = data.customerPhone
          this.thirdOrderObj.customerAddress = data.customerAddress
          this.thirdOrderObj.pddIdentifyNumber = data.pddIdentifyNumber
          this.thirdOrderObj.pddVirtualNumberType = data.pddVirtualNumberType
        })
      },
      // 市修改事件
      doChangeCity(provinceCode, cityCode, townCode) {
        this.cityList = []
        this.districtList = []
        this.thirdOrderObj.customerCityCode = ''
        this.thirdOrderObj.customerDistrictCode = ''
        if (provinceCode) {
          listCity(provinceCode).then(response => {
            this.cityList = response.data
          })
          this.thirdOrderObj.customerCityCode = cityCode
          this.doChangeDistrict(cityCode, townCode)
        }
      },
      // 区修改事件
      doChangeDistrict(cityCode, townCode) {
        this.districtList = []
        this.thirdOrderObj.customerDistrictCode = ''
        if (cityCode) {
          listDistrict(cityCode).then(response => {
            this.districtList = response.data
          })
          this.thirdOrderObj.customerDistrictCode = townCode
        }
      },
      // 保存事件
      doSave() {
        this.loading = true
        saveThirdOrder(this.thirdOrderObj).then(response => {
          if (response.isError) {
            this.loading = false
            return
          }
          this.$message.success('保存成功')
          this.init()
        })
      },
      // 更新地址事件
      doSaveReceiveInfo() {
        this.loading = true
        updateReceiveInfo(this.thirdOrderObj).then(response => {
          this.loading = false
          if (response.isError) return
          const msg = this.thirdOrderObj.platformType === 1 ? '修改内容已发送平台，请等待平台自动确认更新' : '保存成功'
          this.$message.success(msg)
        })
      },
      // 地址审核事件
      doAuditReceiveAddress() {
        this.auditReceiveVisible = true
      },
      // 审核地址回调事件
      doCallbackAuditReceive(callbackFlag) {
        if (callbackFlag) {
          this.init()
        }
        this.auditReceiveVisible = false
      },
      // 生成事件
      doGenerate() {
        this.loading = true
        doGenerateOrder({
          externalOrderNo: this.thirdOrderObj.externalOrderNo,
          shopId: this.thirdOrderObj.shopId,
          platformType: this.thirdOrderObj.platformType
        }).then(response => {
          if (response.isError) {
            this.loading = false
            return
          }
          this.$message.success('生成成功')
          this.init()
        })
      },
      // 上一笔事件
      doJumpPrev() {
        this.$router.push({ path: '/order/third-order/detail', query: { thirdOrderId: this.prevId }})
      },
      // 下一笔事件
      doJumpNext() {
        this.$router.push({ path: '/order/third-order/detail', query: { thirdOrderId: this.nextId }})
      },
      // 删除订单事件
      doDelete() {
        this.$confirm('确定删除订单？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          deleteThirdOrder({ thirdOrderId: this.thirdOrderObj.thirdOrderId }).then(response => {
            this.loading = false
            if (response.isError) return
            this.editFlag = false
            const msg = (this.thirdOrderObj.mergeType === 1 ? '重新同步' : '删除') + '成功, 3秒后将关闭页面'
            this.$message({ message: msg, type: 'success' })
            setTimeout(() => window.close(), 3000)
          })
        }).catch(() => {
        })
      },
      // 返回事件
      doBack() {
        this.$router.go(-1)
      },
      // 重新添加所有事件
      doResetAll() {
        const form = {
          thirdOrderId: this.thirdOrderObj.thirdOrderId
        }
        this.handleReset(form)
      },
      // 重新添加订单商品事件
      doResetSubOrder(row) {
        const form = {
          thirdOrderId: this.thirdOrderObj.thirdOrderId,
          thirdSubOrderId: row.thirdSubOrderId
        }
        this.handleReset(form)
      },
      // 重新添加处理
      handleReset(form) {
        this.$confirm('该操作会根据平台商品编码重新匹配商品，确定重新添加？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          doReset(form).then(response => {
            if (response.isError) {
              this.loading = false
              return
            }
            this.$message({ message: '成功', type: 'success' })
            this.init()
          })
        }).catch(() => {
        })
      },
      // 删除所有订单商品事件
      doDeleteAll() {
        const subOrderIds = this.subOrderList.filter(e => e.delFlag === 0).map(e => e.thirdSubOrderId)
        if (subOrderIds.length === 0) {
          this.$message({ message: '无可删除订单', type: 'warning' })
        }
        this.handleDelete(subOrderIds)
      },
      // 删除订单商品事件
      doDeleteSubOrder(row) {
        const subOrderIds = [row.thirdSubOrderId]
        this.handleDelete(subOrderIds)
      },
      // 删除处理
      handleDelete(thirdSubOrderIds) {
        this.$confirm('确定删除商品？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          deleteSubOrder(thirdSubOrderIds).then(response => {
            if (response.isError) {
              this.loading = false
              return
            }
            this.$message({ message: '删除成功', type: 'success' })
            this.init()
          })
        }).catch(() => {
        })
      },
      // 修改商品事件
      doChangeGoods(row) {
        this.orderGoodsForm = row
        this.selectedGoodsId = ''
        this.selectSkuVisible = true
      },
      // 修改规格事件
      doChangeGoodsSku(row) {
        this.orderGoodsForm = row
        this.selectedGoodsId = row.goodsId
        this.selectSkuVisible = true
      },
      // 商品选择回调事件
      doCallbackSelect(goods) {
        const subOrder = {
          thirdSubOrderId: this.orderGoodsForm.thirdSubOrderId,
          thirdSubOrderComboId: this.orderGoodsForm.thirdSubOrderComboId,
          goodsId: goods.goodsId,
          skuId: goods.skuId
        }
        this.loading = true
        if (subOrder.thirdSubOrderComboId) {
          doChangeCombo(subOrder).then(response => {
            if (response.isError) {
              this.loading = false
              return
            }
            this.$message({ message: '修改成功', type: 'success' })
            this.selectSkuVisible = false
            this.init()
          })
        } else {
          doChange(subOrder).then(response => {
            if (response.isError) {
              this.loading = false
              return
            }
            this.$message({ message: '修改成功', type: 'success' })
            this.selectSkuVisible = false
            this.init()
          })
        }
      },
      // 修改数量事件
      doChangeGoodsNum(row) {
        this.goodNumForm.thirdSubOrderId = row.thirdSubOrderId
        this.goodNumForm.goodsNum = 1
        this.updateGoodsNumVisible = true
      },
      // 添加赠品事件
      updateGoodsNum() {
        this.$refs['goodNumForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            addGift(this.goodNumForm.thirdSubOrderId, this.goodNumForm.goodsNum).then(response => {
              if (response.isError) {
                this.loading = false
                return
              }
              this.updateGoodsNumVisible = false
              this.$message.success('保存成功')
              this.init()
            })
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>
  .base-info {
    width: 100%;
    line-height: 30px;
    .left {
      min-width: 90px;
      text-align: right;
    }
  }
  /deep/ .el-tabs__item {
    font-weight: bold;
  }
</style>
